//
//  CoverViewController.m
//  Tiger
//
//  Created by King on 11-10-18.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CoverViewController.h"
#import "UIImageViewAnimator.h"
#import "TigerAppDelegate.h"

@implementation CoverViewController
//@synthesize animator;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
//	[animator release];
    [p_TigerBlackImg release];
    [super dealloc];
}

- (void) viewDidLoad
{
    [self.view setBackgroundColor:[UIColor blackColor]];
//	NSMutableArray * dataSet = [NSMutableArray arrayWithCapacity:17];
//	for ( int i=0; i<17; i++ )
//	{
//		NSString * name = [NSString stringWithFormat:@"loading%d.png", i];
//		[dataSet addObject:name];
//	}
//	
//	[animator setImageNames:dataSet];
//	[animator setDuration:2.0];
//	
//	//test notification!	
//	[animator setCacheImages:YES];
//	[animator setDelegate:self];
//	
//	[self startAnimation];
//	
//	[animator setStartSelector:@selector(start:)];
//	[animator setStopSelector:@selector(stop:)];
    
    p_TigerBlackImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sani2.png"]];
    p_TigerBlackImg.frame =CGRectMake(0, 0, 320, 480);
    [self.view addSubview:p_TigerBlackImg];
    
    UIImageView* tBlackLayer = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sani3.png"]];
    tBlackLayer.frame =CGRectMake(-320, 0, 320, 480);
    tBlackLayer.tag =10;
    [self.view addSubview:tBlackLayer];
    [tBlackLayer release];
    
    UIView* tRightBlack = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [tRightBlack setBackgroundColor:[UIColor blackColor]];
    tRightBlack.tag =11;
    [self.view addSubview:tRightBlack];
    [tRightBlack release];
    UIView* tLeftBlack = [[UIView alloc] initWithFrame:CGRectMake(-640, 0, 320, 480)];
    [tLeftBlack setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:tLeftBlack];
    tLeftBlack.tag =12;
    [tLeftBlack release];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:4.f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateStop)];
    tBlackLayer.frame =CGRectMake(220, 0, 320, 480);
    tRightBlack.frame =CGRectMake(540, 0, 320, 480);
    tLeftBlack.frame =CGRectMake(-100, 0, 320, 480);
    [UIView commitAnimations];
}

-(void) animateStop
{
    p_TigerBlackImg.hidden =YES;
    UIView* tSubView0 = [self.view viewWithTag:10];
    UIView* tSubView1 = [self.view viewWithTag:11];
    UIView* tSubView2 = [self.view viewWithTag:12];
    
    [tSubView0 removeFromSuperview];
    [tSubView1 removeFromSuperview];
    [tSubView2 removeFromSuperview];
    
    
    
    UIImageView* tLightTigerBlackImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sani4.png"]];
    tLightTigerBlackImg.tag =20;
    tLightTigerBlackImg.frame =CGRectMake(0, 0, 320, 480);
    tLightTigerBlackImg.alpha = 0.f;
    [self.view addSubview:tLightTigerBlackImg];
    [tLightTigerBlackImg release];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:2.f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateLightStop)];
    tLightTigerBlackImg.alpha =1.0f;
    [UIView commitAnimations];
}
-(void) animateLightStop
{
    UIImageView* tLightTigerBlackImg = (UIImageView*)[self.view viewWithTag:20];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateLightDrakStop)];
    tLightTigerBlackImg.alpha =0.1f;
    [UIView commitAnimations];
}

-(void)animateLightDrakStop
{
    UIImageView* tLightTigerBlackImg = (UIImageView*)[self.view viewWithTag:20];
    [tLightTigerBlackImg removeFromSuperview];
    p_TigerBlackImg.hidden =NO;
    p_TigerBlackImg.alpha = 0.1f;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.7f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateShowDrakStop)];
    p_TigerBlackImg.alpha =1.f;
    [UIView commitAnimations];
}
-(void)animateShowDrakStop
{
    UIImageView* tTitleTigerImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sani5.png"]];
    tTitleTigerImg.frame =CGRectMake(0, 0, 320, 480);
    [self.view addSubview:tTitleTigerImg];
    [tTitleTigerImg release];
    
    UIImageView* tTitleCoverImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sani6.png"]];
    tTitleCoverImg.frame =CGRectMake(-220, 0, 320, 480);
    tTitleCoverImg.tag =30;
    [self.view addSubview:tTitleCoverImg];
    [tTitleCoverImg release];
    
    
    UIView* tRightBlack = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 320, 100)];
    [tRightBlack setBackgroundColor:[UIColor blackColor]];
    tRightBlack.tag =31;
    [self.view addSubview:tRightBlack];
    [tRightBlack release];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:3.f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateAllOverStop)];
    tTitleCoverImg.frame =CGRectMake(320, 0, 320, 480);
    tRightBlack.frame =CGRectMake(640, 380, 320, 100);
    [UIView commitAnimations];
}

-(void)animateAllOverStop
{
    TigerAppDelegate *delegate = (TigerAppDelegate*)[[UIApplication sharedApplication] delegate];
	[self.view removeFromSuperview];
	[delegate.window addSubview:delegate.customviewController.view];
}
//-(void)start:(id)_context
//{
//	NSLog( @"Animation playback has been triggered" );
//}

//- (void) stop:(id)_context
//{
//	NSLog( @"Animation playback has finished" );
//	//self.window.rootViewController = self.coverViewController;
//
////	[delegate.window setRootViewController:delegate.customviewController];
//	
//}
//
//- (void) startAnimation
//{
//	if ( ![animator isAnimating] )
//	{
//		[animator setIndex:0];
//		[animator startAnimating];
//	}
//}


@end
